//package com.sportizz.sport;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import org.json.JSONArray;
//import org.json.JSONException;
//
//import com.sportizz.model.PlayerData;
//import com.sportizz.model.player_search;
//import com.sportizz.sport.MainActivity.PlayerAdapter1;
//
//import android.app.Activity;
//import android.app.ProgressDialog;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Color;
//import android.os.AsyncTask;
//import android.os.Bundle;
//import android.text.Editable;
//import android.text.TextWatcher;
//import android.util.Log;
//import android.view.KeyEvent;
//import android.view.View;
//import android.view.inputmethod.EditorInfo;
//import android.view.inputmethod.InputMethodManager;
//import android.widget.AdapterView;
//import android.widget.AutoCompleteTextView;
//import android.widget.Button;
//import android.widget.TextView;
//import android.widget.AdapterView.OnItemClickListener;
//import android.widget.TextView.OnEditorActionListener;
//
//public class New_search_act extends Activity{
//
//	AutoCompleteTextView search_text ;
//	Button clear_txt;
//	
//	ProgressDialog pd;
//	
//	@Override
//	protected void onCreate(Bundle savedInstanceState) {
//		// TODO Auto-generated method stub
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.new_search_lay);
//		
//		search_text = (AutoCompleteTextView) findViewById(R.id.search_name_text);
//		clear_txt = (Button) findViewById(R.id.clear_txt_search);
//		
//		final PlacesAutoCompleteAdapter placeadapter = new PlacesAutoCompleteAdapter(
//				this, R.layout.list_item);
//
//		search_text.addTextChangedListener(new TextWatcher() {
//
//			@Override
//			public void onTextChanged(CharSequence arg0, int arg1, int arg2,
//					int arg3) {
//				search_text.setAdapter(placeadapter);
//				placeadapter.notifyDataSetChanged();
//			}
//
//			@Override
//			public void beforeTextChanged(CharSequence arg0, int arg1,
//					int arg2, int arg3) {
//
//			}
//
//			@Override
//			public void afterTextChanged(Editable arg0) {
//				placeadapter.notifyDataSetChanged();
//			}
//		});
//		placeadapter.notifyDataSetChanged();
//		
//		search_text.setOnEditorActionListener(new OnEditorActionListener() {
//
//			@Override
//			public boolean onEditorAction(TextView arg0, int actionId,
//					KeyEvent arg2) {
//				
//				 if (actionId == EditorInfo.IME_ACTION_SEARCH) {
////					 final PlacesAutoCompleteAdapter placeadapter = new PlacesAutoCompleteAdapter(
////								MainActivity.this, R.layout.list_item);
////
////						search_text.setAdapter(placeadapter);
////						placeadapter.notifyDataSetChanged();
//					 Log.d("suraj","Enter Action Search Resuylt = ");
//					 
//					 final ArrayList<String> search_list = new ArrayList<String>();
//					 final List<player_search> pl_search=new ArrayList<player_search>();
//					 MainActivity.result_main = new ArrayList<String>();
//						
//					 
//					final New_PlacesAutoAdapter new_placeadapter =new New_PlacesAutoAdapter(New_search_act.this,search_list,pl_search);
//					 search_text.setAdapter(new_placeadapter);
//					 
//					 
//					 AsyncTask<Void, Void, ArrayList<String>> search_wait = new AsyncTask<Void, Void, ArrayList<String>>()
//					 {
//						 
//						@Override
//						protected void onPostExecute(ArrayList<String> result) {
//							// TODO Auto-generated method stub
//							super.onPostExecute(result);
//							
//							MainActivity.result_main = result;
//							new_placeadapter.notifyDataSetChanged();
//							pd.dismiss();
//							
//						}
//
//						@Override
//						protected void onPreExecute() {
//
//							pd = ProgressDialog.show(New_search_act.this, "", "Searching...",
//									true);
//							super.onPreExecute();
//						}
//
//						@Override
//						protected ArrayList<String> doInBackground(Void... params) {
//
//							String sch_txt = search_text.getText().toString().replace(" ", "%20");
//							
//							String search_responce = Utils.readJsonFeed("http://sportizza.com/interface/autocomplete.php?term="+sch_txt+"", New_search_act.this);
//							
//							Log.d("suraj","Search Resuylt = "+search_responce);
//							try {
//								JSONArray predsJsonArray = new JSONArray(search_responce);
//
//								pl_search.clear();
//								
//								for (int i = 0; i < predsJsonArray.length(); i++) {
//
//
//									pl_search.add(new player_search(predsJsonArray
//											.getJSONObject(i).getString("ss_player_name"),
//											predsJsonArray.getJSONObject(i).getString(
//													"ss_player_code"),
//											predsJsonArray.getJSONObject(i).getString(
//													"ss_sport"), predsJsonArray
//													.getJSONObject(i).getString(
//															"ss_is_team")));
//
//									search_list.add(predsJsonArray.getJSONObject(i).getString(
//											"ss_player_name")
//											+ ":"
//											+ predsJsonArray.getJSONObject(i).getString(
//													"ss_player_code")
//											+ ":"
//											+ predsJsonArray.getJSONObject(i).getString(
//													"ss_sport")
//											+ ":"
//											+ predsJsonArray.getJSONObject(i).getString(
//													"ss_is_team"));
//
//								}
//							} catch (JSONException e) {
//								Log.e("suraj", "Cannot process JSON results", e);
//							}
//							
//							
//							return search_list;
//						}
//						 
//					 };
//					 search_wait.execute();
//					 
//			            return true;
//			        }
//				return false;
//			}
//
//		});
//		placeadapter.notifyDataSetChanged();
//		
//		search_text.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> adapter, View myView,
//					final int position, long arg3) {
//
//				 InputMethodManager imm = (InputMethodManager)getSystemService(
//					      Context.INPUT_METHOD_SERVICE);
//					imm.hideSoftInputFromWindow(search_text.getWindowToken(), 0);
//					
//								String all_data = MainActivity.result_main
//										.get(position);
//
//								Log.w("suraj", "str=" + all_data);
//
////								String[] items = all_data.split(":");
//
//								Intent data=new Intent();
//								data.putExtra("key", all_data);
//								setResult(200, data);
//								finish();
//								
//			}
//
//		});
//	}
//}
